


#delimit;
set more off;

cd "C:\....\Replication files";
	
use "ENMI - replication.dta", clear;


/**** combine the natural pairs	****/

gen i1= ((per102*total + per101*total)/total);
gen i2= ((per104*total + per105*total) / total);
gen i3= ((per109*total + per107*total)/total);
gen i4= ((per110*total + per108*total)/total);
gen i5= ((per204*total + per203*total)/total);
gen i6= ((per302*total + per301*total)/total);
gen i7= ((per406*total + per407*total)/total);
gen i8= ((per414*total + per409*total)/ total);
gen i9= ((per601*total + per602*total) /total);
gen i10= ((per603*total + per604*total) /total);
gen i11= ((per608*total + per607*total) /total);
gen i12= ((per702*total + per701*total) /total);
gen i13= ((per504*total + per505*total ) /total);
gen i14= ((per507*total + per506*total) /total); 
	
 #delimit;
 set more off;
 
/* Generate the Issue overlap measure from Sigelman and Buell 2004*/

foreach i in i1 per103 i2 per106  i3 i4 per201 per202 i5 i6 per303 per304 per305 per401 per402 per403 per404 per405 i7
		 per408 i8 per410 per411 per412 per413  per415 per416 per501 per502 per503 i13 i14 
	i9 i10 per605 per606 i11 i12 per703 per704 per705 per706 {;

egen avg_`i'= mean(`i'), by( edate country);
gen dif_`i'=abs(`i' - avg_`i');

};
 egen issue_overlap= rowtotal(dif_*);
egen largest_opp=max(pvote_l) if inc_cab_l==0, by(edate country);
 gen opp_enmi= ensh_mi if largest_opp== pvote_l;
egen opposition_enshmi = max(opp_enmi), by(edate country);
egen opp_avgenshmi=mean(ensh_mi ) if inc_cab_l==0, by(country edate);
	egen opposition_avgenshmi= max(opp_avgenshmi), by(edate country);
 
 egen avg_enshmi=mean(ensh_mi ), by(country edate);
/* Green-Pedersen and Mortenson	2010*/
/* generate Opposition party emphasis and party system agenda measures	*/
		egen equil_pvote= mean(pvote) , by(party);
	gen pvote_lag= L1.pvote - equil_pvote;



	gen ln_issue_overlap= ln(issue_overlap +.5);
	gen ln_ensh_mi= ln(ensh_mi);
	
	
set more off;
xtreg pvote
	c.ensh_mi##1.inc_cab_l
	pvote_l ,
 fe robust;

 estimate store ENMI_ioverlap_simple;

xtreg pvote
	c.ensh_mi##1.inc_cab_l 
	
	pvote_l
	c.GDPgrowth##1.inc_cab_l
	1.moderate##1.inc_cab_l
c.L1.opposition_avgenshmi##1.inc_cab_l
L1.avg_enshmi
	1.nparty
 majelect federal directpres ,
 fe robust;

		 estimates store ENMI_ioverlap_full;	

		 xtreg pvote
	c.ensh_mi  
	pvote_l
	c.GDPgrowth
	1.moderate
L1.opposition_avgenshmi
L1.avg_enshmi
	1.nparty
 majelect federal directpres if inc_cab_l==0,
 fe robust;
		
		 estimates store ENMI_ioverlap_opponly;	
	
	
	xtreg pvote
	c.ensh_mi 
	pvote_l
	c.GDPgrowth#1.inc_cab_l
	1.moderate#1.inc_cab_l
c.L1.opposition_avgenshmi
L1.avg_enshmi 
	1.nparty
 majelect federal directpres if inc_cab_l==1,
 fe robust;
		 estimates store ENMI_ioverlap_incumbentonly;
	
	
	
	


	 #delimit;
 esttab  ENMI_ioverlap_opponly ENMI_ioverlap_incumbentonly ENMI_ioverlap_full 
 using "figures\Table A21 - party system agenda.rtf", replace 
		b (%10.3f) se scalars("aic AIC" "bic BIC" "rmse Root Mean Squared Error" "ll Log-Likelihood" ) 
		obslast star(+ 0.10 * 0.05 ** 0.01 *** 0.001)
		label mtitles ( "Opposition" "Incumbents" "Full") nogaps
		title (\label{})
order(ensh_mi 
1.inc_cab_l#c.ensh_mi 

L.opposition_avgenshmi
1.inc_cab_l#cL.opposition_avgenshmi
L.avg_enshmi
L.avg_enshmi#inc_cab_l
moderate 
inc_cab_l#moderate
GDPgrowth
1.inc_cab_l#c.GDPgrowth 
1.inc_cab_l 
 majelect pvote_l _cons )
 
keep(ensh_mi 1.inc_cab_l 
1.inc_cab_l#c.ensh_mi GDPgrowth 
1.inc_cab_l#c.GDPgrowth 
inc_cab_l#moderate
moderate majelect 
pvote_l L.opposition_avgenshmi
1.inc_cab_l#cL.opposition_avgenshmi
L.avg_enshmi
L.avg_enshmi#inc_cab_l _cons ) 

 coeflabels(
ensh_mi "ENMI" 
1.inc_cab_l "Incumbent"
1.inc_cab_l#c.ensh_mi "Incumbent X ENMI"
GDPgrowth "GDP Growth Rate" 
1.inc_cab_l#c.GDPgrowth "Incumbent X GDP Growth Rate"
inc_cab_l#moderate "Incumbent X Moderated Position"
L.opposition_avgenshmi "Average Opposition ENMI, t-1"
1.inc_cab_l#cL.opposition_avgenshmi  "Incumbent X Average Opposition ENMI, t-1"
L.avg_enshmi  "Party System ENMI, t-1"
L.avg_enshmi#inc_cab_l "Incumbent X Party System ENMI, t-1"
moderate "Moderated Position"
majelect "Majoritarian Election"
pvote_l "% Vote{\sub t-1}"
_cons "Constant")
addnotes("Note: The Dependent variable is percentage vote for the party.");



/* Run the 2SLS with teh party system agenda variabes	*/
 
 	#delimit;
	set more off;
 ivregress  2sls pvote
	 pvote_l c.issue_overlap
	  c.GDPgrowth
	 c.moderate
L.opposition_enshmi L.avg_enshmi
 majelect 
	 (  c.ensh_mi= L.opposition_enshmi L.avg_enshmi issue_overlap 
	 GDPgrowth totalcod dsle)
	 	if inc_cab_l==0, vce(cluster edate_numeric) first ;

		estimates store opp_2sls_issueoverlap;
			#delimit;
	set more off;
	
 ivregress  2sls pvote

	 pvote_l c.issue_overlap#1.inc_cab_l
	  c.GDPgrowth#1.inc_cab_l
	 c.moderate#1.inc_cab_l 
c.L.opposition_enshmi#1.inc_cab_l 
	 c.L.avg_enshmi#1.inc_cab_l
 majelect 
	 (  c.ensh_mi#1.inc_cab_l = 
	 c.L.opposition_enshmi#1.inc_cab_l 
	 c.L.avg_enshmi#1.inc_cab_l issue_overlap 
	 GDPgrowth totalcod dsle)
	 	if inc_cab_l==1, vce(cluster edate_numeric) first ;
		estimates store inc_2sls_issueoverlap;
		
			#delimit;
	set more off;
 ivregress  2sls pvote
	 pvote_l c.issue_overlap##1.inc_cab_l c.ensh_mi
	  c.GDPgrowth##1.inc_cab_l
	 c.moderate##1.inc_cab_l 
c.L.opposition_enshmi##1.inc_cab_l  
c.L.avg_enshmi##1.inc_cab_l
 majelect 
	 (c.ensh_mi#1.inc_cab_l = L.opposition_enshmi 
	 L.avg_enshmi issue_overlap 
	 GDPgrowth totalcod dsle), vce(cluster edate_numeric) first ;

				estimates store full_2sls_issueoverlap;
		
		 #delimit;
 esttab  opp_2sls_issueoverlap inc_2sls_issueoverlap full_2sls_issueoverlap 
 using "figures\Table A20 - 2SLS Party system agenda.rtf", replace 
		b (%10.3f) se scalars("aic AIC" "bic BIC" "rmse Root Mean Squared Error" "ll Log-Likelihood" ) 
		obslast star(+ 0.10 * 0.05 ** 0.01 *** 0.001)
		label mtitles ( "Opposition" "Incumbents" "Full") nogaps
		title (\label{})

order(ensh_mi 
1.inc_cab_l#c.ensh_mi 
issue_overlap
1.inc_cab_l#c.issue_overlap
L.opposition_enshmi
1.inc_cab_l#cL.opposition_enshmi
L.avg_enshmi
1.inc_cab_l#cL.avg_enshmi
moderate 
1.inc_cab_l#c.moderate
GDPgrowth
1.inc_cab_l#c.GDPgrowth 
1.inc_cab_l 
 majelect pvote_l _cons ) 

keep(ensh_mi 1.inc_cab_l 
1.inc_cab_l#c.ensh_mi 
issue_overlap
1.inc_cab_l#c.issue_overlap
L.opposition_enshmi
1.inc_cab_l#cL.opposition_enshmi
L.avg_enshmi
1.inc_cab_l#cL.avg_enshmi
GDPgrowth 
1.inc_cab_l#c.GDPgrowth 
1.inc_cab_l#c.moderate
moderate majelect 
pvote_l 

L.avg_enshmi
1.inc_cab_l#cL.avg_enshmi _cons ) 

 coeflabels(
ensh_mi "ENMI" 
1.inc_cab_l "Incumbent"
1.inc_cab_l#c.ensh_mi "Incumbent X ENMI"
issue_overlap "Issue Overlap"
1.inc_cab_l#c.issue_overlap "Incumbent X Iss Overlap"
L.opposition_enshmi "Average Opposition ENMI{\sub t-1}"
1.inc_cab_l#cL.opposition_enshmi  "Incumbent X Average Opposition ENMI{\sub t-1}"
L.avg_enshmi  "Party System ENMI{\sub t-1}"
1.inc_cab_l#cL.avg_enshmi  "Incumbent X Party System ENMI{\sub t-1}"

GDPgrowth "GDP Growth Rate" 
1.inc_cab_l#c.GDPgrowth "Incumbent X GDP Growth Rate"
1.inc_cab_l#c.moderate "Incumbent X Moderated Position"

moderate "Moderated Position"
majelect "Majoritarian Election"
pvote_l "% Vote{\sub t-1}"
_cons "Constant")
addnotes("Note: The Dependent variable is percentage vote for the party.");
